package rest.jbpm.svg;

import org.dom4j.Element;

/**
 * Created by IntelliJ IDEA.
 * User: xEviL
 * Date: 26.10.11
 * Time: 15:06
 * To change this template use File | Settings | File Templates.
 */
class JbpmElementFactory {
    public static JbpmElement createElement(Element el){
        String[] elCoords = el.attribute("g").getValue().split(",");
        Integer elX = Integer.parseInt(elCoords[0]);
        Integer elY = Integer.parseInt(elCoords[1]);
        Integer elW = Integer.parseInt(elCoords[2]);
        Integer elH = Integer.parseInt(elCoords[3]);

        String el_name = el.attribute("name").getValue();
        String el_type = el.getName();

        if (el_type.equalsIgnoreCase("end-error"))
            return new JbpmEndErrorElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("start"))
            return new JbpmStartElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("end"))
            return new JbpmEndElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("end-cancel"))
            return new JbpmEndCancelElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("fork"))
            return new JbpmJoinForkElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("join"))
            return new JbpmJoinForkElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
        if (el_type.equalsIgnoreCase("decision"))
            return new JbpmDecisionElement(el.attribute("name").getValue(),elX,elY,elW,elH);
        else
            return new JbpmElement(el.attribute("name").getValue(),elX,elY,elW,elH);//el.getName()+":"+
    }
}
